package com.dq;

import org.apache.catalina.startup.Tomcat;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @ClassName TomcatCondition
 * @Description 加载tomcat配置类条件
 * @Author DuX1aoQiang
 * @Date 2023/5/19 21:39
 * @Version 1.0
 */
public class TomcatCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //判断pom.xml 是否有这个依赖
        try {
            context.getClassLoader().loadClass("org.apache.catalina.startup.Tomcat");
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }
    }
}
